<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.hilaver.dzmis.Constants"%>
<%@ page import="com.hilaver.dzmis.service.impl.CtServiceImpl"%>
<%@ page import="com.hilaver.dzmis.service.impl.ProcurementServiceImpl"%>
<%@ page import="com.hilaver.dzmis.service.impl.I18nServiceImpl"%>
<%@ page import="com.hilaver.dzmis.codetable.*"%>
<%@ page import="com.hilaver.dzmis.procurement.Procurement"%>
<%@ page import="com.hilaver.dzmis.product.*"%>
<%@ page import="com.hilaver.dzmis.basicinfo.BiAccessoryButton"%>
<%
	Integer id = Integer.parseInt(request.getParameter("id"));
	CtServiceImpl cs = new CtServiceImpl();
	ProcurementServiceImpl ps = new ProcurementServiceImpl();
	I18nServiceImpl i18n = new I18nServiceImpl();
	Locale locale = (Locale) request.getSession().getAttribute(
			Constants.SESSION_LOCALE);
	ps.setLocale(locale);
	Procurement procurement = ps.getObj(id);
	Set<ProductIdentification> piSet = procurement
			.getProductIndentifications();
	List<BiAccessoryButton> abList = ps.getDiffButton(piSet);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
<link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
<title><%=procurement.getName()%>--<%=i18n.getShortMessage(locale, "ui.procurement.button") %></title>
</head>
<body>
<%for(int i = 0; i < abList.size(); i ++){
	List<ProductIdentification> piList = ps.getProductIdentificationFromButton(piSet, abList.get(i));
%>
	<table cellspacing="0" id="the-table" style="width: 60%;float: left;margin-bottom: 25px;">
		<tr>
			<td style="background:#eeeeee;text-align: center;" colspan="<%=piList.size()*2 + 1 %>"><b><%
						if(piList.size() > 0 && piList.get(0).getBiFranceCustomer() != null){
							out.print(piList.get(0).getBiFranceCustomer().getName());
							if(piList.get(0).getBiFranceCustomer().getDepartment() != null){
								out.print("--" + piList.get(0).getBiFranceCustomer().getDepartment());
							}
							
						}
						
					%>&nbsp;&nbsp;<%=abList.get(i).getReference() %>&nbsp;&nbsp;<%=i18n.getShortMessage(locale, "ui.accessorybutton.refcolor") %></b></td>
		</tr>
		<tr>
			<td style="text-align: center; width: 100px;"><b><%=i18n.getShortMessage(locale, "ui.productidentification.seasonnumber") %>&nbsp;&nbsp;<%=(piList.size()>0?cs.getDescription(CtSeasonNumber.class.getName(), piList.get(0).getCtSeasonNumber(), locale):"") %></b></td>
			<% for(int j = 0; j < piList.size(); j ++){ %>
				<td colspan="2" style="text-align: center;">
					<b><%=piList.get(j).getReference() %></b>
				</td>
			<%} %>
		</tr>
		<tr>
			<td style="text-align: center;"><b><%=i18n.getShortMessage(locale, "ui.productidentification.color") %></b></td>
			<% for(int j = 0; j < piList.size(); j ++){ %>
				<td style="text-align: center;">
					<font style="color: red; font-weight: bold;"><%=i18n.getShortMessage(locale, "ui.accessorybutton.color") %></font>
				</td>
				<td style="text-align: center;">
					<b>
					<%
						if(piList.get(j).getBiFranceCustomer() != null){
							out.print(piList.get(j).getBiFranceCustomer().getName());
							if(piList.get(j).getBiFranceCustomer().getDepartment() != null){
								out.print("--" + piList.get(j).getBiFranceCustomer().getDepartment());
							}
							
						}
						
					%>&nbsp;&nbsp;&nbsp;&nbsp;<%=i18n.getShortMessage(locale, "ui.accessorybutton.quantity") %></b>
				</td>
			<%} %>
		</tr>
		<% List<String> colorList = ps.getDiffColor(piSet, abList.get(i)); 
			for(int j = 0; j < colorList.size(); j ++){ %>
				<tr>
					<td style="text-align: center;">
						<%=colorList.get(j) %>
					</td>
					<% for(int k = 0; k < piList.size(); k ++){ %>
						<td style="text-align: center;">
							<font style="color: red;"><%=ps.getButtonColorFrom(piList.get(k), colorList.get(j)) %></font>
						</td>
						<td style="text-align: center;">
							<%=ps.getButtonQuantityFrom(piList.get(k), colorList.get(j)) %>
						</td>
					<%} %>
				</tr>
		<%  } %>
	</table>
	<table cellspacing="0" id="the-table" style="width: 35%;float: right;">
		<tr style="background:#eeeeee;">
			<td style="text-align: center;">
				<b><%=i18n.getShortMessage(locale, "ui.accessorybutton.reference") %></b>
			</td>
			<td style="text-align: center;">
				<font style="color: red; font-weight: bold;"><%=i18n.getShortMessage(locale, "ui.accessorybutton.color") %></font>
			</td>
			<td style="text-align: center;">
				<font style="font-weight: bold;"><%=i18n.getShortMessage(locale, "ui.accessorybutton.minquantity") %></font>
			</td>
		</tr>
		<% List<String> buttonColorList = ps.getDiffButtonColor(piSet, abList.get(i));
			for(int j = 0; j < buttonColorList.size(); j ++){ %>
				<tr>
					<%if(j ==0){ %>
						<td rowspan="<%=buttonColorList.size() %>" style="text-align: center;">
							<font style="color: red; font-weight: bold;text-align: center;"><%=abList.get(i).getReference() %>&nbsp;(<%=abList.get(i).getMeasure() %>)</font>
						</td>
					<%} %>
					<td style="text-align: center;">
						<%=buttonColorList.get(j) %>
					</td>
					<td style="text-align: center;"><%=ps.getButtonTotalQuantity(piSet, abList.get(i), buttonColorList.get(j)) %></td>
				</tr>
		<%  } %>
	</table>
<%}%>

<table cellspacing="0" id="the-table" style="width: 100%;float: left;margin-top: 25px;">
	<tr>
		<td style="background:#eeeeee;text-align: center;" colspan="<%=piSet.size() + 1 %>"><b><%=procurement.getName() %>&nbsp;&nbsp;<%=i18n.getShortMessage(locale, "ui.accessorybutton.refcolor") %></b></td>
	</tr>
	<tr>
		<td style="text-align: center; width: 120px;">
			<b><%=i18n.getShortMessage(locale, "ui.reference.reference") %></b>
		</td>
		<%for(ProductIdentification pi : piSet){ %>
			<td style="text-align: center;">
				<%=pi.getReference() %>
			</td>
		<%} %>
	</tr>
	<tr>
		<td style="text-align: center;">
			<b><%=i18n.getShortMessage(locale, "ui.accessorybutton.reference") %></b>
		</td>
		<%for(ProductIdentification pi : piSet){
			List<ProductAccessoryButton> pabList = ps.getDiffProductButton(pi);
		%>
			<td style="text-align: center;">
				<% 
					for(int i = 0; i < pabList.size(); i ++){
						out.print(pabList.get(i).getBiAccessoryButton().getReference());
						if(i != pabList.size() - 1){
							out.print("&nbsp;/&nbsp;");
						}
					}
				%>
			</td>
		<%} %>
	</tr>
	<tr>
		<td style="text-align: center;">
			<b><%=i18n.getShortMessage(locale, "ui.accessorybutton.measure") %>&nbsp;(mm)</b>
		</td>
		<%for(ProductIdentification pi : piSet){
			List<ProductAccessoryButton> pabList = ps.getDiffProductButton(pi);
		%>
			<td style="text-align: center;">
				<% 
					for(int i = 0; i < pabList.size(); i ++){
						out.print(pabList.get(i).getBiAccessoryButton().getMeasure());
						if(i != pabList.size() - 1){
							out.print("&nbsp;/&nbsp;");
						}
					}
				%>
			</td>
		<%} %>
	</tr>
	<tr>
		<td style="text-align: center;">
			<b><%=i18n.getShortMessage(locale, "ui.accessorybutton.ribbonreference") %></b>
		</td>
		<%for(ProductIdentification pi : piSet){
			List<ProductAccessoryButton> pabList = ps.getDiffProductButton(pi);
		%>
			<td style="text-align: center;">
				<% 
					for(int i = 0; i < pabList.size(); i ++){
						out.print(pabList.get(i).getRibbonReference());
						if(i != pabList.size() - 1){
							out.print("&nbsp;/&nbsp;");
						}
					}
				%>
			</td>
		<%} %>
	</tr>
	<tr>
		<td style="background:#eeeeee;text-align: center;">
			<b><%=i18n.getShortMessage(locale, "ui.productidentification.color") %></b>
		</td>
		<td style="background:#eeeeee;text-align: center;" colspan="<%=piSet.size() %>">
			<font style="color: red; font-weight: bold;"><%=i18n.getShortMessage(locale, "ui.accessorybutton.color") %></font>&nbsp;&nbsp;-&nbsp;&nbsp;<font style="color: blue;font-weight: bold;"><%=i18n.getShortMessage(locale, "ui.accessorybutton.ribboncolor") %></font>
		</td>
	</tr>
<% 
	List<String> piColorList = ps.getDiffColorFrom(piSet);
	for(int i = 0; i < piColorList.size(); i ++){
%>
	<tr>
		<td style="text-align: center;">
			<b><%=piColorList.get(i) %></b>
		</td>
		<%for(ProductIdentification pi : piSet){
			List<ProductAccessoryButton> pabList = ps.getDiffProductButton(pi);
		%>
			<td style="text-align: center;">
				<% 
						out.print("<font style=\"color: red;\">");
						Set<ProductOrderItem> pois = pi.getProductOrderItems();
						for (ProductOrderItem poi : pois) {
							Set<ProductAccessoryButton> pabs = poi.getProductAccessoryButtons();
							for (ProductAccessoryButton pab : pabs) {
								if(poi.getColorNumber().equals(piColorList.get(i))){
									out.print(pab.getBiAccessoryButton().getCustomerColor()+ "&nbsp;&nbsp;");
								}
							}
						}
						out.print("</font>&nbsp;&nbsp;-&nbsp;&nbsp;<font style=\"color: blue;\">");
						for (ProductOrderItem poi : pois) {
							Set<ProductAccessoryButton> pabs = poi.getProductAccessoryButtons();
							for (ProductAccessoryButton pab : pabs) {
								if(poi.getColorNumber().equals(piColorList.get(i))){
									out.print(pab.getRibbonColor()+ "&nbsp;&nbsp;");
								}
							}
						}
						out.print("</font>");
				%>
			</td>
		<%} %>
	</tr>
<%} %>
</table>
</body>
</html>